
#include <bits/stdc++.h>
#define LL long long

using namespace std;
const int MAXN = 5000 + 5;
int n, m;
int w[MAXN];
vector<int> G[MAXN];
LL dis[MAXN][MAXN];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    scanf("%d", w + i);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }


  for (int v = 1; v <= n; ++v) {
    for (int j = 0; j <= n - 1; ++j) {
      dis[v][j] = 1e18;
    }
  }

  for (int j = 0; j <= n - 1; ++j)
    dis[1][j] = 0;

  for (int j = n - 1; j >= 1; --j) {
    for (int v = 1; v <= n; ++v) {
      for (auto x : G[v]) {
        // (v,j) -> (x, j-1)
        dis[x][j - 1] = min(dis[x][j - 1], dis[v][j] + 1ll * w[v] * j);
      }
    }
  }

  for (int i = 1; i <= n; ++i)
    printf("%lld\n", dis[i][0]);
  return 0;
}